﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Sunisoft.IrisSkin;

namespace lchealthy
{
    public partial class frmadmin : Form
    {
        public static Sunisoft.IrisSkin.SkinEngine se = null;
        Image im = null;
        public bool isrelogin = false;
        public static void InitMenu(ToolStripMenuItem tsMi, EventHandler e)
        {
            DirectoryInfo dirinfo = new DirectoryInfo(Application.StartupPath + @"\skins");
            FileInfo[] allfile = dirinfo.GetFiles("*.ssk");
            se.AddtionalBuiltInSkins.Clear();
            //int i = 0;
            ToolStripMenuItem no = new ToolStripMenuItem();          
            
            no.Text = "不使用皮肤";
            no.Tag = "no";// +"|" + i;
            no.Click += new EventHandler(e);
            tsMi.DropDownItems.Add(no);
            foreach (FileInfo fi in allfile)
            {
                ToolStripMenuItem temp = new ToolStripMenuItem();
                string str = fi.Name;
                string filename = str.Substring(0, str.IndexOf('.'));
                temp.Text = filename;
                temp.Tag = fi.FullName;// +"|" + i;
                temp.Click += new EventHandler(e);
                tsMi.DropDownItems.Add(temp);
                //Sunisoft.IrisSkin.SkinCollectionItem s =new SkinCollectionItem();
                //s.SkinFile = temp.Tag.ToString();
                //se.AddtionalBuiltInSkins.Add(s);
                //i++;
            }


        }
        public frmadmin()
        {
            InitializeComponent();
        }

        private void 产品添加ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmNewProduct f = new frmNewProduct();
            f.MdiParent = this;
            f.Show();
        }

        private void frmadmin_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (!isrelogin)
            {
                if (MessageBox.Show("您真的要退出吗？", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    Application.ExitThread();
                }
                else
                {
                    e.Cancel = true;
                }
            }
        }

        private void frmadmin_Load(object sender, EventArgs e)
        {
            if (userinfo.isadmin)
            {
                this.系统管理ToolStripMenuItem.Visible = true;
                this.用户管理ToolStripMenuItem.Visible = true;
                this.产品添加ToolStripMenuItem.Visible = true;
                this.产品浏览ToolStripMenuItem.Visible = true;
                this.入库记录ToolStripMenuItem.Visible = false;
                this.库存浏览ToolStripMenuItem.Visible = false;
                this.客户管理ToolStripMenuItem.Visible = false;
                this.tsmiskin.Visible = false;
                this.toolStripButton3.Visible = false;
                this.toolStripButton4.Visible = false;
            }
            else
            {
                this.系统管理ToolStripMenuItem.Visible =false;
                this.用户管理ToolStripMenuItem.Visible = false;
                this.产品添加ToolStripMenuItem.Visible = false;
                this.产品浏览ToolStripMenuItem.Visible = false;
                this.入库记录ToolStripMenuItem.Visible = true;
                this.库存浏览ToolStripMenuItem.Visible = true;
                this.toolStripButton3.Visible = true;
                this.toolStripButton4.Visible = true;

            }
            se = new Sunisoft.IrisSkin.SkinEngine();
            se.SkinAllForm = true;
            InitMenu(this.tsmiskin, toolStripMenu_Click);
            frmbg();
            setstatus();
        }
        //状态条
        public void setstatus()
        {
            toolStripStatusLabel1.Text = shopinfo.name;
            toolStripStatusLabel2.Text = shopinfo.add;
            toolStripStatusLabel3.Text = userinfo.name;
            toolStripStatusLabel4.Text = userinfo.tel;
            toolStripStatusLabel5.Text = DateTime.Now.ToString();
        }
        public void frmbg()
        {
            string file = Application.StartupPath + "\\bg.jpg";
            if (File.Exists(file))
            {
                im = Image.FromFile(file);
                this.BackgroundImage = im;
            }
        }
        public void frmbgc()
        {
            if (this.BackgroundImage != null)
            {
                this.BackgroundImage = null;
                im.Dispose();

            }
            
                
        }
        private void toolStripMenu_Click(object sender, EventArgs e)
        {
            ToolStripMenuItem temp = (ToolStripMenuItem)sender;
            if (temp.Tag.ToString() != "no")
            {
                myfun.Modify(Application.StartupPath, "skin",temp.Tag.ToString());
                //Sunisoft.IrisSkin.SkinEngine s = new SkinEngine();                
                se.RemoveForm(this,true);
                se.SkinFile = temp.Tag.ToString();
                se.AddForm(this);
                //se.Active = true;
                this.Refresh();
                //string file = temp.Tag.ToString().Split('|')[0];
                //int index = int.Parse(temp.Tag.ToString().Split('|')[1]);
                //se.ApplyAdditionalBuiltInSkins(index);
                //保存设置
                //myfun.Modify(Application.StartupPath, "skin", file);
            }
            else
            {
                //不用皮肤
                myfun.Modify(Application.StartupPath, "skin", "");
                se.RemoveForm(this, true);
                se.Active = false;
            }


        }

        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            //frmtest f = new frmtest(1);
            //f.MdiParent = this;
            //f.Show();
            frmCustomerShow f = new frmCustomerShow();
            f.MdiParent = this;
            f.Show();
            //frmtestlist f = new frmtestlist();
            //f.MdiParent = this;
            //f.Show();
        }

        private void 产品浏览ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmProductShow f = new frmProductShow();
            f.MdiParent = this;
            f.Show();
        }

        private void 客户测量ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            
        }

        private void tsmicl_Click(object sender, EventArgs e)
        {
            frmjftop f = new frmjftop();
            f.MdiParent = this;
            f.Show();
        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            frmtest f = new frmtest(1);
            f.MdiParent = this;
            f.Show();

        }

        private void 客户添加ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmCustomer f = new frmCustomer();
            f.MdiParent = this;           
            f.Show();
            f.WindowState = FormWindowState.Maximized;
        }

        private void 入库记录ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmininventoryshow f = new frmininventoryshow();
            f.MdiParent = this;
            f.Show();
        }

        private void 库存浏览ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmInventoryShow f = new frmInventoryShow();
            f.MdiParent = this;
            f.Show();
        }

      

        private void toolStripButton3_Click(object sender, EventArgs e)
        {
            frmInventory f = new frmInventory();
            f.MdiParent = this;
            f.Show();
        }

        private void toolStripButton4_Click(object sender, EventArgs e)
        {
            frmInventoryShow f = new frmInventoryShow();
            f.MdiParent = this;
            f.Show();
        }

        private void 营养师添加ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmNewDietitian f = new frmNewDietitian();
            f.MdiParent = this;
            f.Show();
        }

        private void 客户浏览ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmCustomerShow f = new frmCustomerShow();
            f.MdiParent = this;
            f.Show();
        }

        private void 顾客用品浏览ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmCustorInventer f = new frmCustorInventer();
            f.MdiParent = this;
            f.Show();
        }

        private void 营养师浏览ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmDietitianShow f = new frmDietitianShow();
            f.MdiParent = this;
            f.Show();
        }

        private void 店面设置ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmshop f = new frmshop();
            f.MdiParent = this;
            f.Show();
            //frmbg();
        }

        private void 系统管理员设置ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmPwd f = new frmPwd();
            f.MdiParent = this;
            f.Show();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            toolStripStatusLabel5.Text = DateTime.Now.ToString();
        }

        private void 入库ToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            frmInventory f = new frmInventory();
            f.MdiParent = this;
            f.Show();
        }

        private void 切换用户ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            myform.frmlogin.Show();
            isrelogin = true;
            this.Close();
            
        }

        private void toolStripButton5_Click(object sender, EventArgs e)
        {
            frmBusiness f = new frmBusiness();
            f.MdiParent = this;
            f.Show();
        }

    }
}
